package com.example.bai11;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity {

	public final static int REQUEST_CODE_INPUT =113;
	public final static int RESULT_CODE_SAVE1=115;
	public final static int RESULT_CODE_SAVE2 =116;
	ArrayList<String> arr;
	ArrayAdapter<String> adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnpopup= (Button) findViewById(R.id.btnpopup);
        btnpopup.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent= new Intent(MainActivity.this, InputActivity.class);
				startActivityForResult(intent,REQUEST_CODE_INPUT);
			}
		});
        ListView list= (ListView) findViewById(R.id.list);
        arr= new ArrayList<String>();
        adapter= new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,arr);
        list.setAdapter(adapter);
    }

    
    @Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode== REQUEST_CODE_INPUT)
		{
			int res=data.getIntExtra("data", 0);
			switch(resultCode)
			{
				case RESULT_CODE_SAVE1:
				{
					res=res*res;
				break;
				}
				case RESULT_CODE_SAVE2:
				{
				break;
				}
				default:
				
				{
				break;
				}
			}
			arr.add(String.valueOf(res));
			adapter.notifyDataSetChanged();
		}
	}


	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
